#include "snakefield.h"

SnakeField::SnakeField(QObject *parent) :
    QObject(parent)
{
    fieldSize.first = 0;
    fieldSize.second = 0;
}

void SnakeField::setFieldSize(Point size)
{
    fieldSize = size;
    field.resize(size.first);
    Field::iterator it = field.begin();
    while(it != field.end())
    {
        it->resize(size.second);
        it++;
    }
}

void SnakeField::setField(QString map)
{
    quint32 poz = 0;
    Field::iterator it = field.begin();
    while(it != field.end())
    {
        QVector<Cell >::iterator jt = it->begin();
        while(jt != it->end())
        {
            quint32 newPoz = map.indexOf(' ', poz);
            QString subStr;
            if(newPoz != -1)
            {
                subStr = map.mid(poz, newPoz - poz);
                poz = newPoz + 1;
            }
            else
            {
                subStr = map.mid(poz);
                poz = map.size();
            }
            *jt = subStr.toInt();
            jt++;
        }
        it++;
    }
}

Field SnakeField::getField()
{
    return field;
}

Point SnakeField::getFieldSize()
{
//    Point ret;
//    ret.first = 0;
//    ret.second = 0;
//    ret.first = field.size();
//    if(ret.first)
//        ret.second = field.at(0).size();
    return fieldSize;
}
